home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / tk / tkmenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  2.9 KB  |  113 lines

  1. /* Midnight Commander/Tk: Pulldown menu code.
  2.    Copyright (C) 1995 Miguel de Icaza
  3.    
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <config.h>
  19. #include <string.h>
  20. #include <malloc.h>
  21. #include "main.h"
  22. #include "tkmain.h"
  23. #include "mad.h"
  24. #include "menu.h"
  25.  
  26. /* Unused but required by the rest of the code */
  27. int menubar_visible = 1;
  28.  
  29. static int
  30. tkmenu_callback (ClientData cd, Tcl_Interp *interp,
  31.          int argc, char *argv [])
  32. {
  33.     callfn callback = (callfn) cd;
  34.  
  35.     is_right = (argv [1][0] != '1');
  36.     (*callback)();
  37.     return TCL_OK;
  38. }
  39.  
  40. /* We assume that menu titles are only one word length */
  41. Menu create_menu (char *name, menu_entry *entries, int count)
  42. {
  43.     int i;
  44.     char *xname = strdup (name), *p;
  45.     static int menu_number;
  46.     
  47.     /* Lower case string, Tk requires this */
  48.     for (p = xname; *p; p++){
  49.     if (*p < 'a')
  50.         *p |= 0x20;
  51.     }
  52.     /* And strip trailing space            */
  53.     *(p-1) = 0;
  54.     
  55.     /* Strip leading space */
  56.     for (p = xname; *p == ' '; p++)
  57.     ;
  58.  
  59.     menu_number++;
  60.     tk_evalf ("create_menu %s %s", name, p);
  61.     for (i = 0; i < count; i++){
  62.     if (entries [i].text [0]){
  63.         char cmd_name [20];
  64.  
  65.         sprintf (cmd_name, "m%d%s", i, p);
  66.         Tcl_CreateCommand (interp, cmd_name, tkmenu_callback,
  67.             entries [i].call_back, NULL);
  68.         tk_evalf ("create_mentry %s {%s } %s %d", p, entries [i].text,
  69.               cmd_name, menu_number);
  70.     } else
  71.         tk_evalf ("add_separator %s", xname);
  72.     }
  73.     free (xname);
  74.     return 0;
  75. }
  76.  
  77. static int menubar_callback (Dlg_head *h, WMenu *menubar, int msg, int par)
  78. {
  79.     if (msg == WIDGET_FOCUS)
  80.     return 0;
  81.     
  82.     return default_proc (h, msg, par);
  83. }
  84.  
  85. static int menubar_event (Gpm_Event *event, WMenu *menubar)
  86. {
  87.     return MOU_NORMAL;
  88. }
  89.  
  90. static void menubar_destroy (WMenu *menubar)
  91. {
  92.     /* nothing yet */
  93. }
  94.  
  95. WMenu *menubar_new (int y, int x, int cols, Menu menu [], int items)
  96. {
  97.     WMenu *menubar = (WMenu *) xmalloc (sizeof (WMenu), "menubar_new");
  98.  
  99.     init_widget (&menubar->widget, y, x, 1, cols,
  100.                  (callback_fn) menubar_callback,
  101.          (destroy_fn)  menubar_destroy,
  102.          (mouse_h)     menubar_event);
  103.     menubar->menu = menu;
  104.     menubar->active = 0;
  105.     menubar->dropped = 0;
  106.     menubar->items = items;
  107.     menubar->selected = 0;
  108.     widget_want_cursor (menubar->widget, 0);
  109.     
  110.     return menubar;
  111. }
  112.  
  113.